package com.hdu.other.tanxin;


import java.util.Arrays;

public class lc2449 {
    class Solution {
        public long makeSimilar(int[] nums, int[] target) {

            int len1 = sort(nums);
            int len2 = sort(target);
            Arrays.sort(nums, 0, len1);
            Arrays.sort(nums, len1, nums.length);
            Arrays.sort(target, 0, len2);
            Arrays.sort(target, len2, target.length);
            int ans = 0;
            for (int i = 0; i < nums.length; i++)
            {
                ans += Math.abs(nums[i] - target[i]);
            }
            return ans / 4;
        }

        int sort(int[] nums)
        {
            int size = 0;
            for (int i = 0; i < nums.length; i++)
            {
                if (nums[i] % 2 == 1)
                {
                    swap(nums, i, size++);
                }
            }
            return size;
        }

        void swap(int[] nums, int i, int j)
        {
            int tmp = nums[i];
            nums[i] = nums[j];
            nums[j] = tmp;
        }
    }
}
